package com.base.caselib;

import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.arvin.imagepicker.bean.ImageItem;
import com.arvin.imagepicker.widget.ImagePickView;
import com.base.caselib.bean.CaseBean;
import com.base.caselib.bean.CaseDetailBean;
import com.base.caselib.bean.CaseType;
import com.base.caselib.bean.CheckBoxBean;
import com.base.caselib.bean.DropBean;
import com.base.caselib.databinding.ActivityCaseEditBinding;
import com.base.caselib.presenter.CaseEditPresenter;
import com.base.caselib.view.CaseEditView;
import com.base.caselib.widget.CheckBoxCustom;
import com.base.caselib.widget.DateCustom;
import com.base.caselib.widget.EditNumCustom;
import com.base.caselib.widget.EditTextCustom;
import com.base.caselib.widget.SingleCheckCustom;
import com.base.caselib.widget.SpinnerCustom;
import com.base.caselib.widget.TitleCustom;
import com.base.commonlib.base.CBaseBarMvpActivity;
import com.base.commonlib.event.AddressEvent;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.utils.RxBus2;
import com.base.commonlib.utils.ToastUtil;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Created by Administrator on 2019/10/21.
 * 案件编辑
 */

@Route(path = "/case/caseedit")
public class CaseEditActivity extends CBaseBarMvpActivity<CaseEditPresenter> implements CaseEditView {
    @Autowired()
    public String cformId;
    @Autowired()
    public String id;

    //案件流程
    ArrayList<CaseType> mListCastType = null;
    List<LinearLayout> mLayout = new ArrayList<>();
    private ActivityCaseEditBinding mBinding;
    private String mNextStateValue = "";

    @Autowired
    String ID;
    @Autowired
    int num;

    private List<EditTextCustom> mAddressCustom = new ArrayList<>();
    private List<ImageItem> ls = new ArrayList<>();
    private CaseDetailBean.CaseEvidence caseEvidence;
    private List<CaseDetailBean.CaseEvidence> caseEvidenceList;
    @Override
    protected int getLayoutResource() {
        return R.layout.activity_case_edit;
    }

    @Override
    protected void init() {
        super.init();
        mBinding = (ActivityCaseEditBinding) mRootBinding;
        setBackNavigationTip(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mWaringDialog.show();
            }
        });
        mPresenter = new CaseEditPresenter(this,this);
        mPresenter.ID = ID;
        mPresenter.isSimple = num;
        mPresenter.start();
        mPresenter.getInfoCasedetail(cformId,id);

    }

    @Override
    protected void start() {
        mBinding.update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPresenter.updataCase(mLayout);
            }
        });
        mBinding.saveDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                for (CaseDetailBean.ModulesBean bean : mPresenter.mCaseBean.getModules()){
                    if (bean.getModuleTitle().equals("隐藏信息")){
                        for (CaseBean.ModulesBean.RowsBean mRow : bean.getRows()){
                            if (mRow.getFieldSave().equals("next_case_status")){
                                mNextStateValue = mRow.getFixValue();
                            }
                        }
                    }
                }
                ARouter.getInstance().build("/pretrial/pret")
                        .withString("mFormId",mPresenter.mCaseBean.getId())
                        .withString("CaseId",id)
                        .withString("tbFlag",mPresenter.mCaseBean.getFormMainValue())
                        .withString("content",mPresenter.mCaseBean.getFormTitle())
                        .withString("nextCaseStatus",mNextStateValue)
                        .withParcelableArrayList("casetype",mListCastType)
                        .navigation();
            }
        });
        Disposable disposable = RxBus2.getInstance().doSubscribe(AddressEvent.class, new Consumer<AddressEvent>() {
            @Override
            public void accept(AddressEvent randomRefreshEvent) throws Exception {
                if (mAddressCustom.size()>0){
                    for (EditTextCustom custom : mAddressCustom){
                        custom.setmEtText(randomRefreshEvent.getAddress());
                    }
                }
            }
        });
        RxBus2.getInstance().addSubscription(this, disposable);
        mBinding.print.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showMes("建设中");
            }
        });
    }


    private List<View> getAllChildViews(View view) {
        List<View> allchildren = new ArrayList<View>();
        if (view instanceof ViewGroup) {
            ViewGroup vp = (ViewGroup) view;
            for (int i = 0; i < vp.getChildCount(); i++) {
                View viewchild = vp.getChildAt(i);
                allchildren.add(viewchild);
                //再次 调用本身（递归）
                allchildren.addAll(getAllChildViews(viewchild));
            }
        }
        return allchildren;
    }




    @Override
    public void returnCaseBean(CaseDetailBean bean) {
        mPresenter.setmCaseBean(bean);
        if (mPresenter.isSimple == 2) {
            mBinding.saveDetail.setVisibility(View.VISIBLE);
            mBinding.save.setVisibility(View.GONE);
            mBinding.update.setVisibility(View.VISIBLE);
            //请求操作步骤
            mPresenter.getInfoByProType();
        }else if (mPresenter.isSimple ==1){
            mBinding.saveDetail.setVisibility(View.GONE);
            mBinding.save.setVisibility(View.GONE);
            mBinding.print.setVisibility(View.VISIBLE);
        }else {
            mBinding.saveDetail.setVisibility(View.GONE);
            mBinding.save.setVisibility(View.GONE);
        }
        setBarTitle(bean.getFormTitle());
        for (CaseDetailBean.ModulesBean models : bean.getModules()){
            if (models.getChildValues() != null) {
                for (CaseDetailBean.ModulesBean.ChildValuesBean childValueBean : models.getChildValues()) {
                    if (childValueBean.getPic()!=null){
                       try {
                           caseEvidence = new Gson().fromJson(childValueBean.getPic(), new TypeToken<CaseDetailBean.CaseEvidence>() {
                           }.getType());
                           if (caseEvidence.getContent().startsWith("http")){
                               ls.add(new ImageItem(caseEvidence.getContent(), caseEvidence.getName()));
                           }else {
                               ls.add(new ImageItem(RealNetWorkUtil.getBaseUrl() + "api-file/" + caseEvidence.getContent(), caseEvidence.getName()));
                           }
                       }catch (JsonSyntaxException e){
                           e.printStackTrace();
                           caseEvidenceList = new Gson().fromJson(childValueBean.getPic(), new TypeToken<List<CaseDetailBean.CaseEvidence>>() {
                           }.getType());
                           for (CaseDetailBean.CaseEvidence it :caseEvidenceList){
                               if (it.getContent().startsWith("http")){
                                   ls.add(new ImageItem(it.getContent(), it.getName()));
                               }else {
                                   ls.add(new ImageItem(RealNetWorkUtil.getBaseUrl() + "api-file/" + it.getContent(), it.getName()));
                               }
                           }
                       }

                    }
                }
            }
        }

        for (CaseDetailBean.ModulesBean models : bean.getModules()){
            createModels(models);
        }



    }

    @Override
    public void saveSuccess(String Id) {
        ToastUtil.show("更新成功");
        if (mPresenter.isSimple == 2) {
            mBinding.saveDetail.setVisibility(View.VISIBLE);
            mBinding.save.setVisibility(View.GONE);
            mBinding.update.setVisibility(View.VISIBLE);
            //请求操作步骤
            mPresenter.getInfoByProType();
        }else if (mPresenter.isSimple ==1){
            mBinding.saveDetail.setVisibility(View.GONE);
            mBinding.save.setVisibility(View.GONE);
            mBinding.print.setVisibility(View.VISIBLE);
        }else {
            mBinding.saveDetail.setVisibility(View.GONE);
            mBinding.save.setVisibility(View.GONE);
        }
    }


    @Override
    public void returnCaseTypeList(List<CaseType> mCaseType) {
        mListCastType = (ArrayList<CaseType>) mCaseType;
    }


    private void createModels(CaseDetailBean.ModulesBean models){
        //创建模块
        final TitleCustom titleCustom = new TitleCustom(mContext);
        titleCustom.setmTvName(models.getModuleTitle());
        final LinearLayout mLinearLayout=new LinearLayout(this);
        mLinearLayout.setOrientation(LinearLayout.VERTICAL);
        mLinearLayout.setTag(models.getModuleIndex());
        mLinearLayout.addView(titleCustom);
        mBinding.root.addView(mLinearLayout);

        final LinearLayout chilLayout=new LinearLayout(this);
        chilLayout.setOrientation(LinearLayout.VERTICAL);
        mLinearLayout.addView(chilLayout);
        //模块显示隐藏
        titleCustom.setTxImgResource(R.drawable.ic_shouqi);
        titleCustom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (chilLayout.getVisibility() == View.VISIBLE){
                    chilLayout.setVisibility(View.GONE);
                    titleCustom.setTxImgResource(R.drawable.ic_xiala);
                }else {
                    chilLayout.setVisibility(View.VISIBLE);
                    titleCustom.setTxImgResource(R.drawable.ic_shouqi);
                }
            }
        });
        mLayout.add(mLinearLayout);
        for (CaseBean.ModulesBean.RowsBean row : models.getRows()){
            if (models.getIsHide()==1){
                mLinearLayout.setVisibility(View.GONE);
            }


            createRow(row,chilLayout,models.getModuleIndex()+"",models);
        }
    }
    //创建行
    private void createRow(final CaseBean.ModulesBean.RowsBean row, final LinearLayout layout, final String mIndex, final CaseDetailBean.ModulesBean modulesBean){

        if (row.getConType().equals("string")){
            EditTextCustom custom = null;
            if (row.getRowLabel().contains("地点")||row.getRowLabel().contains("地址")){
                custom = new EditTextCustom(mContext,1);
                mAddressCustom.add(custom);
            }else {
                custom = new EditTextCustom(mContext,0);
            }
            custom.setOnSpiner(mPresenter.mUser.getUserId());
            custom.setmTvName(row.getRowLabel());
            custom.setmRowIndex(row.getRowIndex()+"");
            custom.setTag(row.getRowIndex()+"");
            if (row.getIsRead()==1){
                custom.setReadLine(true);
                custom.setmEtText(row.getValue());
            }else {
                custom.setmEtText(row.getValue());
            }
            layout.addView(custom);
            if (row.getIsHide()==1){
                custom.setVisibility(View.GONE);
            }
        }else if(row.getConType().equals("int")){
            //数字输入框
            EditNumCustom custom = new EditNumCustom(mContext);
            custom.setmTvName(row.getRowLabel());
            custom.setmRowIndex(row.getRowIndex()+"");
            custom.setTag(row.getRowIndex()+"");
            if (row.getIsRead()==1){
                custom.setReadLine(true);
            }
            custom.setmEtText(row.getValue());
            layout.addView(custom);
            if (row.getIsHide()==1){
                custom.setVisibility(View.GONE);
            }
        }else if (row.getConType().equals("date")){
            //date 日期输入框
            DateCustom custom = new DateCustom(mContext);
            custom.setmTvName(row.getRowLabel());
            custom.setmRowIndex(row.getRowIndex()+"");
            custom.setTag(row.getRowIndex()+"");
            custom.setY(true);
            custom.setDefaultTime(false);
            if (row.getIsNow()==1){

                custom.setmTvDate(row.getValue());
            }else {
                custom.setmTvDate(row.getValue());
            }
            layout.addView(custom);
            if (row.getIsHide()==1){
                custom.setVisibility(View.GONE);
            }
        }else if (row.getConType().equals("datetime")){
            //日期输入框 年月日时分秒
            DateCustom custom = new DateCustom(mContext);
            custom.setmTvName(row.getRowLabel());
            custom.setmRowIndex(row.getRowIndex()+"");
            custom.setTag(row.getRowIndex()+"");
            custom.setDefaultTime(false);
            if (row.getIsNow()==1){
                custom.setmTvDate(row.getValue());
            }else {
                custom.setmTvDate(row.getValue());
            }
            layout.addView(custom);
            if (row.getIsHide()==1){
                custom.setVisibility(View.GONE);
            }
        }else if (row.getConType().equals("text")){
            //大文本输入框
            EditTextCustom custom = null;
            if (row.getRowLabel().contains("地点")||row.getRowLabel().contains("地址")){
                mAddressCustom.add(custom);
                custom = new EditTextCustom(mContext,1);
            }else {
                custom = new EditTextCustom(mContext,0);
            }
            custom.setOnSpiner(mPresenter.mUser.getUserId());
            custom.setmTvName(row.getRowLabel());
            custom.setTag(row.getRowIndex()+"");
            custom.setmEtText(row.getValue());
            custom.setmRowIndex(row.getRowIndex()+"");
            layout.addView(custom);
            if (row.getIsHide()==1){
                custom.setVisibility(View.GONE);
            }
        }else if (row.getConType().equals("dropdown")){
            List<CheckBoxBean> checkBoxBeans = new Gson().fromJson(row.getFillValueOptions(),new TypeToken<List<CheckBoxBean>>(){}.getType());
            Map<String, String> stringStringMap = null;
            if (row.getConShowIndex() != "{}") {
                stringStringMap = new Gson().fromJson(row.getConShowIndex(), new TypeToken<Map<String, String>>() {
                }.getType());
            }

            //下拉选择框
            final SpinnerCustom custom = new SpinnerCustom(mContext);
            custom.setTag(row.getRowIndex()+"");
            custom.setmName(row.getRowLabel());
            custom.setRow(row);
            custom.setmRowIndex(row.getRowIndex()+"");
            custom.setCurrentModelIndex(mIndex);

            List<CheckBoxBean> fillValueOptionsBeans = new Gson().fromJson(row.getFillValueOptions(), new TypeToken<List<CheckBoxBean>>() {
            }.getType());

            if (TextUtils.isEmpty((String)row.getValue())){

            }else {
                if (fillValueOptionsBeans.size() ==0){
                    //请求数据
                    //获取联动数据
                    Map<String,String> parmes = new HashMap<>();
                    parmes.put("dropValue",row.getSelectFieldValue());
                    parmes.put("dropLabel",row.getSelectFieldLabel());
                    parmes.put("dropTable",row.getSelectTableValue());
                    parmes.put("dropConditionFormula",row.getDropFunction());
                    List<DropBean> list = new Gson().fromJson(row.getDropJsonArr(),new TypeToken<List<DropBean>>(){}.getType());
                    for (DropBean dropBean : list){
                        if (dropBean.getRank().equals("02200002")){
                            //获取模块索引
                            if (mLayout != null&&mLayout.size()>0){
                                for (LinearLayout view : mLayout) {
                                    if (view != null) {
                                        if (view.getTag() != null) {
                                            if (view.getTag().toString().equals(String.valueOf(modulesBean.getModuleIndex()))) {
                                                //获取到该模块
                                                List<View> views = getAllChildViews(view);
                                                for (View view1 :views){
                                                    if (view1 instanceof SpinnerCustom){
                                                        SpinnerCustom custom1 = (SpinnerCustom) view1;
                                                        if (custom1.getRowIndex().equals(dropBean.getValue())){
                                                            if (row.getRowLabel().contains("违法行为")){
                                                                dropBean.setValue(custom1.getCurrentValue());
                                                            }else {
                                                                dropBean.setValue(row.getValue());
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    parmes.put("dropConditionFormula",row.getDropFunction());
                    parmes.put("dropConditionJson",new Gson().toJson(list));
                    mPresenter.getFieldValue(parmes,custom,true,row.getValue());
                }else {
                    for (CheckBoxBean bean : fillValueOptionsBeans) {
                        if (bean.getDropValue().equals((String) row.getValue())) {
                            custom.setDefault(bean);
                        }
                    }
                }
            }

            custom.setMapKeyValue(stringStringMap);
            custom.setOnCheckListener(new SpinnerCustom.OnCheckFuOnClick() {
                @Override
                public void onCheckedListener(CheckBoxBean bean, String modeIndex,String mLastModelIndex) {
                    if (row.getIsConHide() == 1) { //有控制隐藏
                        if (row.getConHideType().equals("2")){ //控制模块
                            //显示模块
                            if (mLayout != null&&mLayout.size()>0){
                                for (View view : mLayout){
                                    if (view != null){
                                        if (view.getTag() != null){
                                            if (view.getTag().toString().equals(modeIndex)) {
                                                view.setVisibility(View.VISIBLE);
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }else if (row.getConHideType().equals("1")){
                            //控制当前行
                            String[] strs = new String[0];
                            if (modeIndex!=null){
                                strs = modeIndex.split(",");
                            }

                            String[] laststrs = new String[0];
                            try {
                                laststrs = mLastModelIndex.split(",");
                            }catch (NullPointerException e){
                                e.printStackTrace();
                            }
                            for (String last : laststrs){
                                if (layout != null&&layout.getChildCount()>0){
                                    for (View view : getAllChildViews(layout)){
                                        if (view != null){
                                            if (view.getTag() != null){
                                                if (view.getTag().toString().equals(last)) {
                                                    view.setVisibility(View.GONE);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            for (String s : strs){
                                if (layout != null&&layout.getChildCount()>0){
                                    for (View view : getAllChildViews(layout)){
                                        if (view != null){
                                            if (view.getTag() != null){
                                                if (view.getTag().toString().equals(s)) {
                                                    view.setVisibility(View.VISIBLE);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                        }else {

                        }


                    }

                }

                @Override
                public void onUnCheckListener(CheckBoxBean bean, String modeIndex) {
                    if (row.getIsConHide() == 1) { //有控制隐藏
                        if (row.getConHideType().equals("2")) { //控制模块
                            //隐藏模块
                            if (mLayout != null&&mLayout.size()>0){
                                for (View view : mLayout) {
                                    if (view != null) {
                                        if (view.getTag() != null) {
                                            if (view.getTag().toString().equals(modeIndex)) {
                                                view.setVisibility(View.GONE);
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }else if (row.getConHideType().equals("1")){
                            //控制当前行
                        }
                    }



                }

                @Override
                public void onRequestList(CheckBoxBean bean, String modeIndex,boolean isFirstCreate) {
                    //获取联动数据
                    Map<String,String> parmes = new HashMap<>();
                    parmes.put("dropValue",row.getSelectFieldValue());
                    parmes.put("dropLabel",row.getSelectFieldLabel());
                    parmes.put("dropTable",row.getSelectTableValue());
                    parmes.put("dropConditionFormula",row.getDropFunction());
                    List<DropBean> list = new Gson().fromJson(row.getDropJsonArr(),new TypeToken<List<DropBean>>(){}.getType());
                    for (DropBean dropBean : list){
                        if (dropBean.getRank().equals("02200002")){
                            //获取模块索引
                            if (mLayout != null&&mLayout.size()>0){
                                for (LinearLayout view : mLayout) {
                                    if (view != null) {
                                        if (view.getTag() != null) {
                                            if (view.getTag().toString().equals(modeIndex)) {
                                                //获取到该模块
                                                List<View> views = getAllChildViews(view);
                                                for (View view1 :views){
                                                    if (view1 instanceof SpinnerCustom){
                                                        SpinnerCustom custom1 = (SpinnerCustom) view1;
                                                        if (custom1.getRowIndex().equals(dropBean.getValue())){
                                                            dropBean.setValue(custom1.getCurrentValue());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    parmes.put("dropConditionFormula",row.getDropFunction());
                    parmes.put("dropConditionJson",new Gson().toJson(list));
                    mPresenter.getFieldValue(parmes,custom,isFirstCreate);
                }
            });
            layout.addView(custom);
            if (row.getIsHide()==1){
                custom.setVisibility(View.GONE);
            }
        }else if (row.getConType().equals("onechoice")){
            List<CheckBoxBean> checkBoxBeans = new Gson().fromJson(row.getFillValueOptions(),new TypeToken<List<CheckBoxBean>>(){}.getType());
            Map<String, String> stringStringMap = null;
            if (row.getConShowIndex() != "{}") {
                stringStringMap = new Gson().fromJson(row.getConShowIndex(), new TypeToken<Map<String, String>>() {
                }.getType());
            }

            //单选框
            SingleCheckCustom custom = new SingleCheckCustom(mContext);
            custom.setTag(row.getRowIndex()+"");
            custom.createChrid(checkBoxBeans,row.getRowLabel());
            custom.setmRowIndex(row.getRowIndex()+"");
            custom.setMapKeyValue(stringStringMap);
            List<CheckBoxBean> fillValueOptionsBeans = new Gson().fromJson(row.getFillValueOptions(), new TypeToken<List<CheckBoxBean>>() {
            }.getType());
            if (TextUtils.isEmpty((String)row.getValue())){

            }else {
                for (CheckBoxBean bean : fillValueOptionsBeans) {
                    if (bean.getDropValue().equals((String) row.getValue())) {
                        custom.setDefault(bean.getDropLabel());
                    }

                }
            }
            custom.setOnCheckListener(new SingleCheckCustom.OnCheckFuOnClick() {
                @Override
                public void onCheckedListener(CheckBoxBean bean,String modeIndex,String lastModeIndex) {
                    if (row.getIsConHide() == 1) { //有控制隐藏
                        if (row.getConHideType().equals("2")) { //控制模块
                            if (mLayout != null&&mLayout.size()>0){
                                for (View view : mLayout){
                                    if (view != null){
                                        if (view.getTag() != null){
                                            if (view.getTag().toString().equals(modeIndex)) {
                                                view.setVisibility(View.VISIBLE);
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }else if (row.getConHideType().equals("1")){
                            //控制当前行
                            String[] strs = modeIndex.split(",");
                            String[] laststrs = lastModeIndex.split(",");
                            for (String last : laststrs){
                                if (layout != null&&layout.getChildCount()>0){
                                    for (View view : getAllChildViews(layout)){
                                        if (view != null){
                                            if (view.getTag() != null){
                                                if (view.getTag().toString().equals(last)) {
                                                    view.setVisibility(View.GONE);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            for (String s : strs){
                                if (layout != null&&layout.getChildCount()>0){
                                    for (View view : getAllChildViews(layout)){
                                        if (view != null){
                                            if (view.getTag() != null){
                                                if (view.getTag().toString().equals(s)) {
                                                    view.setVisibility(View.VISIBLE);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }else {

                        }
                    }


                }

                @Override
                public void onUnCheckListener(CheckBoxBean bean,String modeIndex,String lastModeIndex) {
                    if (row.getIsConHide() == 1) { //有控制隐藏
                        if (row.getConHideType().equals("2")) { //控制模块
                            if (mLayout != null&&mLayout.size()>0){
                                for (View view : mLayout) {
                                    if (view != null) {
                                        if (view.getTag() != null) {
                                            if (view.getTag().toString().equals(modeIndex)) {
                                                view.setVisibility(View.GONE);
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }else if (row.getConHideType().equals("1")){
                            //控制当前行
                            String[] strs = modeIndex.split(",");
                            String[] laststrs = lastModeIndex.split(",");
                            for (String last : laststrs){
                                if (layout != null&&layout.getChildCount()>0){
                                    for (View view : getAllChildViews(layout)){
                                        if (view != null){
                                            if (view.getTag() != null){
                                                if (view.getTag().toString().equals(last)) {
                                                    view.setVisibility(View.GONE);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            for (String s : strs){
                                if (layout != null&&layout.getChildCount()>0){
                                    for (View view : getAllChildViews(layout)){
                                        if (view != null){
                                            if (view.getTag() != null){
                                                if (view.getTag().toString().equals(s)) {
                                                    view.setVisibility(View.VISIBLE);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }else {

                        }
                    }

                }
            });
            layout.addView(custom);
            if (row.getIsHide()==1){
                custom.setVisibility(View.GONE);
            }
        }else if (row.getConType().equals("morechoice")){

            List<CheckBoxBean> checkBoxBeans = new Gson().fromJson(row.getFillValueOptions(),new TypeToken<List<CheckBoxBean>>(){}.getType());
            Map<String,String> stringStringMap = null;
            try {
                stringStringMap = new Gson().fromJson(row.getConShowIndex(),new TypeToken<Map<String,String>>(){}.getType());
            }catch (JsonSyntaxException e){
                stringStringMap = new HashMap<>();
            }


            //复选框
            CheckBoxCustom custom = new CheckBoxCustom(mContext);
            custom.setTag(row.getRowIndex()+"");
            custom.createChrid(checkBoxBeans,row.getRowLabel());
            custom.setMapKeyValue(stringStringMap);
            custom.setmRowIndex(row.getRowIndex()+"");
            custom.setOnCheckListener(new CheckBoxCustom.OnCheckFuOnClick() {
                @Override
                public void onCheckedListener(CheckBoxBean bean,String modeIndex,String mLastModelIndex) {
                    if (row.getIsConHide() == 1) { //有控制隐藏
                        if (row.getConHideType().equals("2")){ //控制模块
                            if (mLayout != null && mLayout.size() > 0) {
                                for (View view : mLayout) {
                                    if (view != null) {
                                        if (view.getTag() != null) {
                                            if (view.getTag().toString().equals(modeIndex)) {
                                                view.setVisibility(View.VISIBLE);
                                                return;
                                            }
                                        }
                                    }
                                }
                            }

                        }else if (row.getConHideType().equals("1")){
                            //控制当前行
                            String[] strs = modeIndex.split(",");
                            String[] laststrs = mLastModelIndex.split(",");
                            for (String last : laststrs){
                                if (layout != null&&layout.getChildCount()>0){
                                    for (View view : getAllChildViews(layout)){
                                        if (view != null){
                                            if (view.getTag() != null){
                                                if (view.getTag().toString().equals(last)) {
                                                    view.setVisibility(View.GONE);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            for (String s : strs){
                                if (layout != null&&layout.getChildCount()>0){
                                    for (View view : getAllChildViews(layout)){
                                        if (view != null){
                                            if (view.getTag() != null){
                                                if (view.getTag().toString().equals(s)) {
                                                    view.setVisibility(View.VISIBLE);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }else {

                        }


                    }

                }



                @Override
                public void onUnCheckListener(CheckBoxBean bean,String modeIndex,String mLastModelIndex) {
                    if (row.getIsConHide() == 1) { //有控制隐藏
                        if (row.getConHideType().equals("2")){ //控制模块
                            if (mLayout != null&&mLayout.size()>0){
                                for (View view : mLayout) {
                                    if (view != null) {
                                        if (view.getTag() != null) {
                                            if (view.getTag().toString().equals(modeIndex)) {
                                                view.setVisibility(View.GONE);
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }else if (row.getConHideType().equals("1")){
                            //控制当前行
                            String[] strs = modeIndex.split(",");
                            String[] laststrs = mLastModelIndex.split(",");
                            for (String last : laststrs){
                                if (layout != null&&layout.getChildCount()>0){
                                    for (View view : getAllChildViews(layout)){
                                        if (view != null){
                                            if (view.getTag() != null){
                                                if (view.getTag().toString().equals(last)) {
                                                    view.setVisibility(View.GONE);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            for (String s : strs){
                                if (layout != null&&layout.getChildCount()>0){
                                    for (View view : getAllChildViews(layout)){
                                        if (view != null){
                                            if (view.getTag() != null){
                                                if (view.getTag().toString().equals(s)) {
                                                    view.setVisibility(View.VISIBLE);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                        }else {

                        }


                    }

                }
            });
            layout.addView(custom);
            if (row.getIsHide()==1){
                custom.setVisibility(View.GONE);
            }
        }else if (row.getConType().equals("up")){
//            final CaseBean.ModulesBean createModel = (CaseBean.ModulesBean) modulesBean.clone();
            //图片上传
            ImagePickView custom = new ImagePickView(mContext,null);
            custom.setTag(row.getRowIndex()+"");
            custom.setmRowIndex(row.getRowIndex()+"");
            custom.setPics(ls);
//            View mView = getLayoutInflater().inflate(R.layout.item_add_delete,null);
//            layout.addView(mView);
            layout.addView(custom);
//            mView.findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    if (createModel != null) {
//                        createModel.setModuleIndex((new Random().nextInt(1000) + 1000));
//                        mPresenter.mCaseBean.getModules().add(createModel);
//                        createModels(modulesBean);
//                    }else {
//                        ToastUtil.show("暂时不可用");
//                    }
//                }
//            });
//            mView.findViewById(R.id.save_delete).setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    LinearLayout layout1 = (LinearLayout) layout.getParent();
//                    layout1.removeAllViews();
//                    mLayout.remove(layout1);
//                    mPresenter.mCaseBean.getModules().remove(createModel);
//                }
//            });


        }else if (row.getConType().equals("upfile")){
            //文件上传
            DateCustom custom = new DateCustom(mContext);
            custom.setTag(row.getRowIndex()+"");
            custom.setmTvName(row.getRowLabel());
            custom.setmRowIndex(row.getRowIndex()+"");
            custom.setmTvDate("文件上传");
            layout.addView(custom);
            if (row.getIsHide()==1){
                custom.setVisibility(View.GONE);
            }
        }
    }
    @Override
    public String getCaseid() {
        return id;
    }
    @Override
    public void onBackPressedSupport() {
        mWaringDialog.show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.release();
    }
}
